//
//  MoBanCellCollection.m
//  MoBan
//
//  Created by apple on 16/7/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "MoBanCellCollection.h"
#import "MoBanUnit.h"
@interface MoBanCellCollection()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,strong)UICollectionView *collectionview;
@property(nonatomic,strong)NSMutableArray *array;
@end
@implementation MoBanCellCollection

-(UICollectionView *)collectionview
{
    if (!_collectionview) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
        layout.minimumInteritemSpacing=0;
        layout.minimumLineSpacing = 0.5;

        _collectionview = [[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:layout];
        _collectionview.dataSource = self;
        _collectionview.delegate = self;
        _collectionview.backgroundColor = [UIColor grayColor];
    }
    return _collectionview;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        NSString *str =  [MoBanUnit ZBCollectionView:reuseIdentifier];
        
        self.collectionview.restorationIdentifier =reuseIdentifier;
        [self.collectionview registerClass:NSClassFromString(str) forCellWithReuseIdentifier:reuseIdentifier];
        [self.contentView addSubview:self.collectionview];
        
    }
    return self;

}
-(void)ZBSetCollectionViewWithArray:(NSMutableArray *)array
{
    self.array = array;
    [self.collectionview reloadData];
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.collectionview.frame = self.bounds;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.array.count;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:self.reuseIdentifier forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    [MoBanUnit ZBCollectionViewCell:cell WithResudentfile:self.reuseIdentifier WithArray:self.array InindexRow:indexPath.row];
    
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [MoBanUnit ZBcollectionViewIteamSizeWith:self.reuseIdentifier];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.deleget respondsToSelector:@selector(ZBMobancellectionview:DidselectdeAtindex:)]) {
        [self.deleget ZBMobancellectionview:collectionView DidselectdeAtindex:indexPath.item];
    }
    
}

@end
